package com.example.test.fragment;

import com.example.test.AddCarNumberActivity;
import com.example.test.R;
import com.example.test.utils.DbDaoUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.DbUtils.DaoConfig;
import com.lidroid.xutils.view.annotation.ViewInject;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class AddCarNumberFragment extends BaseFragment implements OnClickListener {


	@ViewInject(R.id.btn_addcar)
	private Button btn_addcar;
	@ViewInject(R.id.et_carnumber)
	private EditText et_carnumber;
	private String carnumber;
	private long res;
	@Override
	public void initData() {
		// TODO Auto-generated method stub
      btn_addcar.setOnClickListener(this);
	}

	@Override
	public View initView(LayoutInflater inflater) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.addnumber_layout, null);
		ViewUtils.inject(this,view);
		return view;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_addcar:
			if(checkForm()){
				DbDaoUtils dao=new DbDaoUtils(ct);
				carnumber = et_carnumber.getEditableText().toString().trim();
				res = dao.insertCarnumber(carnumber);				
				if(res>0){
					Toast.makeText(ct, "添加成功!", 0).show();
					((AddCarNumberActivity)ct).finish();
				}else {
					Toast.makeText(ct, "添加失败!", 0).show();
				}
				
			}
			break;

		default:
			break;
		}
	}
	private boolean checkForm() {
		// TODO Auto-generated method stub
		carnumber = et_carnumber.getEditableText().toString().trim();		
       if(TextUtils.isEmpty(carnumber)){
    	   Toast.makeText(ct, "Carnumber不能为空", Toast.LENGTH_SHORT).show();
    	   return false;
       }		
		return true;
	}

}
